package com.xggstudio.crm.ui.mvp.p;

import android.util.Log;

import com.xggstudio.crm.api.APIServer;
import com.xggstudio.crm.api.NetCheckerSubscriber;
import com.xggstudio.crm.base.App;
import com.xggstudio.crm.ui.mvp.m.CusListBean;
import com.xggstudio.crm.ui.mvp.v.ICusList;

import rx.Scheduler;
import rx.android.schedulers.AndroidSchedulers;
import rx.internal.schedulers.NewThreadScheduler;
import rx.schedulers.Schedulers;

public class P_CusList {

    private ICusList iCusList;

    public P_CusList(ICusList iCusList) {
        this.iCusList = iCusList;
    }

    public void getData(int page,int count){

        String token = App.getInstance().getLoginBean().getResult().getAccess_token();

        APIServer.getInstence().getServer()
                .getCuaListData(token,page,count)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new NetCheckerSubscriber<CusListBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("P_CusList", "onError: " + e.toString());
                    }

                    @Override
                    public void onNext(CusListBean cusListBean) {

                        if(cusListBean.getCode().equals("1")){
                            iCusList.showData(cusListBean);
                        }else{

                        }

                    }

                    @Override
                    protected void onNoNetError() {
                        iCusList.noNet();
                    }
                });
    }

}
